package com.siss.tenancy.util;/**
 * @Auther: liyipeng
 * @Date: 2020/1/14 15:04
 * @Description:
 */

import java.util.regex.Pattern;

/**
 * <p>类名: IdNoUtil</p>
 * <p>描述:TODO</p>
 * <p>创建人: liyp</p>
 * <p>创建时间: 2020/1/14 15:04</p>
 * <p>@version 2.0  </p>
 * <p>修改内容: ......</p>
 * <p>修改说明: ......</p>
 * <p>修改时间: ......</p>
 * <p>修改人: ......</p>
 * <p>每次修改，请增加上述修改信息说明</>
 */
public class IdNoUtil {

    public static boolean isIdNo(String idNo){
        boolean isMatch = false;
        idNo = idNo.trim();
        //大陆
//        String pattern = "^[1-9]\\d{5}[1-9]\\d{3}((0[1-9])|(1[0-2]))(([0|1|2][1-9])|3[0-1])((\\d{4})|\\d{3}X)$";
        String pattern = "^(\\d{6})(\\d{4})(\\d{2})(\\d{2})(\\d{3})([0-9]|X)$";
        isMatch = idNo.matches(pattern);
        if(!isMatch){
            //香港
            pattern = "^[A-Z]{1,2}[0-9]{6}\\(?[0-9A-Z]\\)?$";
            isMatch = Pattern.matches(pattern, idNo);
        }
        if(!isMatch){
            //台湾
            pattern = "^[a-zA-Z][0-9]{9}$";
            isMatch = Pattern.matches(pattern, idNo);
        }

        if(!isMatch){
            //澳门
            pattern = "^[1|5|7][0-9]{6}\\(?[0-9A-Z]\\)?$";
            isMatch = Pattern.matches(pattern, idNo);
        }
        return isMatch;
    }

    public static void main(String[] args) {
        System.out.println(isIdNo("330102198309200037"));
//        System.out.println(isIdNo("M738981(2)"));
    }
}
